using System;

namespace Source.Common
{
    public static class DateTimeProvider
    {
        private static DateTime? _overriddenCurrentDateTime;

        public static DateTime Now
        {
            get
            {
                if (_overriddenCurrentDateTime == null)
                {
                    return DateTime.Now;
                }
                else
                {
                    return _overriddenCurrentDateTime.Value;
                }
            }
        }

        /// <summary>
        /// This should only be used in the test project
        /// </summary>
        /// <param name="overriddenCurrentDateTime"></param>
        public static void OverrideCurrentDateTime(DateTime overriddenCurrentDateTime)
        {
            _overriddenCurrentDateTime = overriddenCurrentDateTime;
        }

        /// <summary>
        /// This should only be used in the test project
        /// </summary>
        public static void ResetCurrentDateTime()
        {
            _overriddenCurrentDateTime = null;
        }
    }
}